package com.api.gbhg.liuwenbo.version3.api;

import com.alibaba.fastjson.JSON;
import com.api.gbhg.liuwenbo.version2.api.BudgetSectionIncomeApi2;
import com.api.gbhg.liuwenbo.version2.api.CauseApi;
import com.api.gbhg.liuwenbo.version2.pojo.BudgetSectionIncome2;
import com.api.gbhg.liuwenbo.version3.util.ApiUtil;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description 事业合计
 * @Version 3.0
 * @Author lwb
 * @Date
 */
@Path("v3/CauseApi")
public class CauseApi3 {

    private BudgetSectionIncomeApi2 causeApi = new CauseApi();

    @POST
    @Path("/getCauseList")
    @Produces(MediaType.APPLICATION_JSON)
    public String getCauseList(Map param){
        Map msgMap = new HashMap();
        if (param == null ||!param.containsKey("nf") ||!param.containsKey("jz")||!param.containsKey("dw")){
            msgMap.put("code","500");
            msgMap.put("msg","缺少参数 请检查参数是否完整！");
            msgMap.put("data","");
            return JSON.toJSONString(msgMap);
        }

        Map<String, Object> paramFormat = causeApi.paramFormat(param);

        List<BudgetSectionIncome2> Data ;//数据集合

        try {
            Data = causeApi.getCzbksrData(paramFormat);


            Map<String,Object> map = new HashMap<>();
            map.put("事业合计", ApiUtil.structureConversion(Data,paramFormat.get("nf").toString()));

            msgMap.put("code","200");
            msgMap.put("msg","");
            msgMap.put("data",map);
        }catch (Exception e){
            msgMap.put("code","500");
            msgMap.put("msg","程序异常，请联系管理员！");
            msgMap.put("data","");
            return JSON.toJSONString(msgMap);
        }

        return JSON.toJSONString(msgMap);
    }
}
